package date_simpledateformat_APIdemo;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author ChenYongHao
 * @date 2023/4/28 9:20
 * @desc
 */
public class SimpleDateFormatAPIdemo {
    public static void main(String[] args) throws ParseException {
        //1、将日期格式化为字符串
        Date d = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String s = sdf.format(d);
        System.out.println("s = " + s);
        //将字符串格式化为日期
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date d2 = sdf1.parse("2020-07-15 01:02:03");
        System.out.println("d2 = " + d2);
    }
}
